package com.atguigu.jxc.controller;

import com.atguigu.jxc.domain.ErrorCode;
import com.atguigu.jxc.domain.ServiceVO;
import com.atguigu.jxc.entity.DamageList;
import com.atguigu.jxc.entity.User;
import com.atguigu.jxc.service.DamageListService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.util.Map;

/**
 * @author ：Shine
 * @description：
 * @date ：2021/3/23 17:40
 */
@RestController
@RequestMapping("/damageListGoods/")
public class DamageController {

    @Autowired
    private DamageListService damageListService;


    //    http://localhost:8080/damageListGoods/save?damageNumber=BS1605766644460
//保存报损单
    @PostMapping("save")
    public ServiceVO save(DamageList damageList, String damageListGoodsStr, HttpSession session) {
        User user = (User) session.getAttribute("currentUser");
        if (user == null) {
            return new ServiceVO(ErrorCode.PARA_TYPE_ERROR_CODE, ErrorCode.PARA_TYPE_ERROR_MESS);
        }
        damageList.setUserId(user.getUserId());
        System.err.println("damageListGoodsStr:" + damageListGoodsStr);
        return damageListService.save(damageList, damageListGoodsStr);
    }

    //    URL：http://localhost:8080/damageListGoods/list
//    报损单查询
    @PostMapping("list")
    public Map<String, Object> list(String sTime, String eTime) {
        return damageListService.list(sTime, eTime);
    }

    //    http://localhost:8080/damageListGoods/goodsList
    @PostMapping("goodsList")
    public Map<String, Object> goodsList(Integer damageListId) {
        return damageListService.goodsList(damageListId);
    }
}
